#include "MainForm.h"

using namespace Osp::Base;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;

MainForm::MainForm(void)
{
}

MainForm::~MainForm(void)
{
}

bool
MainForm::Initialize()
{
	// Construct an XML form
	Construct(L"IDF_MAINFORM");

	return true;
}

result
MainForm::OnInitializing(void)
{
	result r = E_SUCCESS;

	// TODO: Add your initialization code here

	// Get a button via resource ID
	__pButtonOk = static_cast<Button *>(GetControl(L"IDC_BUTTON_OK"));
	if (__pButtonOk != null)
	{
		__pButtonOk->SetActionId(233);
		__pButtonOk->AddActionEventListener(*this);
	}

	__pPopup = new Popup();
	__pPopup->Construct(true, Osp::Graphics::Dimension(300, 400));
	__pPopup->SetTitleText(L"This is a PopUp");

	// Create a button to close the Popup.
	__pCloseButton = new Button();
	__pCloseButton->Construct(Osp::Graphics::Rectangle(50, 200, 250, 60), L"Close Popup");
	__pCloseButton->SetActionId(234);
	__pCloseButton->AddActionEventListener(*this);
	__pPopup->AddControl(*__pCloseButton);

	return r;
}

result
MainForm::OnTerminating(void)
{
	result r = E_SUCCESS;

	// TODO: Add your termination code here

	return r;
}

void
MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
	case 233:
		{
			__pPopup->SetShowState(true);
			__pPopup->Show();
		}
		break;
	case 234:
		{
			__pPopup->SetShowState(false);
			__pPopup->Show();
			RequestRedraw(true);
		}
		break;
	default:
		break;
	}
}
